function Abin = getagebin(A,nage,nbin)

[nhh,J] = size(A);

if nhh == 1
    
    if nage ==1
    Abin = A;
    else
    Abin = nanmean(reshape(A,nage,nbin));
    end;    
    
    
else 
    meanA = nanmean(A);
    
    if nage ==1
    Abin = meanA;
    else
    Abin = nanmean(reshape(meanA,nage,nbin));
    end;    
    
    
end;
    
    